package com.twu.biblioteca;

import java.util.ArrayList;

public class BookList {
    private ArrayList<BookDetail> bookList;

    public BookList(){
        bookList = new ArrayList<BookDetail>();
        this.initializeBooks();
    }

    private void initializeBooks(){
        bookList.add(new BookDetail("Schindler's List", "Thomas Keneally", "1994"));
        bookList.add(new BookDetail("The Great Gatsby", "F. Scott Fitzgerald", "2004"));
    }

    public BookDetail searchBook(String bookName) throws Exception {
        for(BookDetail book : bookList)
            if(book.getName().equals(bookName))
                return book;

        throw new Exception();

    }

    public void displaybooks() {
        Console console = new Console();
        console.write("ID      Name               Author          Published Year\n");

        int id = 1;

        for(BookDetail book : bookList) {
            if(!book.getCheckedOut() == true){
                console.write(id + "   " + book.toString() + "\n");
                id++;

            }
        }
    }
}
